close all
%this script creates three 'Pitas' clusters
%This example works poorly on K-means,
%FN - works poorly, NN - works well.

z_distance = 20;
c_diameter = 10; %cluster diameter
cluster_size = 45;
C1 = create_cluster([0,0,-z_distance]',[c_diameter, c_diameter, 1]', cluster_size);
C2 = create_cluster([0,0,0]', [c_diameter, c_diameter, 1]', cluster_size);
C3 = create_cluster([0,0,z_distance]', [c_diameter, c_diameter, 1]', cluster_size);

my_ones = ones(1,cluster_size);
colors = [my_ones, my_ones*2, my_ones*3];
C = [C1, C2, C3];
scatter3(C(1,:), C(2,:), C(3,:), [], colors', 'filled');
view(-20,15);
axis equal;
title('Generated Pita clusters')

%classification
figure;
class = kmeans(C', 3, 'replicates',5);
scatter3(C(1,:), C(2,:), C(3,:), [], class', 'filled');
view(-20,15);
axis equal;
rand_index = RandIndex(class, colors);
t = sprintf('K-Means results\nRand Index = %f', rand_index);
title(t)

%trying with dendogram with NN
figure;
class = clusterdata(C', 'maxclust', 3, 'linkage', 'single');
scatter3(C(1,:), C(2,:), C(3,:), [], class', 'filled');
view(-20,15);
axis equal;
rand_index = RandIndex(class, colors);
t = sprintf('hierarchical results - NN\nRand Index = %f', rand_index);
title(t);

%trying with dendogram with FN
figure;
class = clusterdata(C', 'maxclust', 3, 'linkage', 'complete');
scatter3(C(1,:), C(2,:), C(3,:), [], class', 'filled');
view(-20,15);
axis equal;
rand_index = RandIndex(class, colors);
t = sprintf('hierarchical results - FN\nRand Index = %f', rand_index);
title(t);

